package com.Cychat.schedule.controller;

import com.Cychat.commons.entity.ResultMessage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.Cychat.commons.entity.pojo.Pet;
import com.Cychat.schedule.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/schedule/pet")
@CrossOrigin
public class PetController {

    @Autowired
    private PetService petService;

    /**
     * Description : 根据宠物主人ID查询宠物列表
     * ChangeLog : 1. 创建 (2025/10/29 10:21 [Lenovo]);
     * @auther: 谢宝辉
     * date: 2025/10/29:10:21
     * @param ownerId
     * @return com.Cychat.commons.entity.ResultMessage<java.util.List<com.Cychat.commons.entity.pojo.Pet>>
    */
    @GetMapping("/owner/{ownerId}/{userId}")
    public ResultMessage<List<Pet>> getPetsByOwnerId(@PathVariable("ownerId") Integer ownerId, @PathVariable("userId") Long userId) {
        List<Pet> petsByOwnerId = petService.getPetsByOwnerId(ownerId);
        return ResultMessage.success(petsByOwnerId);
    }
    /**
     * Description : 根据宠物ID查询宠物详情
     * ChangeLog : 1. 创建 (2025/10/29 10:21 [Lenovo]);
     * @param petId
     * @return com.Cychat.commons.entity.pojo.Pet
     * @auther: 谢宝辉
     * date: 2025/10/29:10:21
     */
    @GetMapping("/getPetById/{petId}/{userId}")
    public ResultMessage<Pet> getPetById(@PathVariable("petId") Integer petId, @PathVariable("userId") Long userId) {
        LambdaQueryWrapper<Pet> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Pet::getPetId, petId);
        Pet pet = petService.getOne(queryWrapper);
        return ResultMessage.success(pet);
    }
}